# Compiler and linker settings
DEFINES = -ggdb -O0 -std=c++98 -g -Wall -I../include -I../../podserver
#DEFINES = -O0 -std=c++98 -g -Wall -I../include -I../../podserver
LIBS = OGRE CEGUI-OGRE CEGUI OGRENEWT NEWTON OIS openal freealut
CXX = g++
CXXFLAGS = -I/usr/local/include/boost-1_35 $(shell pkg-config --cflags $(LIBS)) $(DEFINES) -include $(PCH_SOURCE)

# Project source and object files
SOURCES:=$(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
PCH_SOURCE=../include/PrecompiledHeaders.h
PCH_OUTPUT=../include/PrecompiledHeaders.h.gch

.PHONY: all
all: $(PCH_OUTPUT) $(OBJECTS)

# if not 'make clean' then include dependency makefiles
ifeq (,$(findstring clean,$(MAKECMDGOALS)))

# include all dependency files
-include $(SOURCES:.cpp=.d)

# generate a .d (file with dependencies for a .o file) from the .cpp file
%.d: %.cpp
	@echo Generating dependency file for $<
	@set -e; rm -f $@; \
	$(CXX) $(CXXFLAGS) -MM -MF $@.temp $<; \
	sed 's,\($*\)\.o[: ]*,\1.o $@ : ,g' < $@.temp > $@; \
	rm -f $@.temp
endif

$(PCH_OUTPUT): $(PCH_SOURCE)
	@echo Precompiling $<
	@$(CXX) $(CXXFLAGS) $< -o $@

# Rule for compiling a .cpp file to a .o file
.cpp.o:
	@echo Compiling $<
	@$(CXX) $(CXXFLAGS) $< -c -o $@

# Remove all object and dependency files and the executable
.PHONY: clean
clean:
	@-rm -f $(SOURCES:.cpp=.d) $(OBJECTS) $(PCH_OUTPUT)
